<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Info_model extends CI_Model {
	public $table = 'info';

	function saveInfo($data){
		if($this->checkUser($data['user_id']) > 0){
			$query = $this->db->update($this->table, $data, "user_id = ".$data['user_id']);
		}else{
			$query = $this->db->insert($this->table, $data);
		}
		return $query;
	}
	
	function getInfo($user_id){
		$query = $this->db->select('*')->from($this->table)->where('user_id', $user_id)->get();
		return $query->result();
	}
	
	function checkUser($user_id){
		$query = $this->db->select('*')->from($this->table)->where('user_id', $user_id)->get();
		return $query->num_rows();
	}
	
	function getImage($user_id){
		$query = $this->db->select('image')->from($this->table)->where('user_id', $user_id)->get();
		return $query->result();
	}
	
	function getLastHistory(){
		$query = $this->db->select('user.uname,'.$this->table.'.updated_date')->from($this->table)
					->join('user', 'user.id = '.$this->table.'.user_id')
					->order_by($this->table.'.updated_date', 'desc')->limit(10)->get();
		return $query->result();
	}
}